package com.jeesite.modules.task.arrange.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.annotation.RepeatSubmit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.task.arrange.entity.DcSupTaskInfoArrange;
import com.jeesite.modules.task.arrange.service.DcSupTaskInfoArrangeService;

import java.util.List;

/**
 * 任务部署信息表-整理任务Controller
 * @author zrr
 * @version 2022-03-07
 */
@Controller
@RequestMapping(value = "${adminPath}/arrange/dcSupTaskInfoArrange")
public class DcSupTaskInfoArrangeController extends BaseController {

	@Autowired
	private DcSupTaskInfoArrangeService dcSupTaskInfoArrangeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupTaskInfoArrange get(String id, boolean isNewRecord) {
		return dcSupTaskInfoArrangeService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("arrange:dcSupTaskInfoArrange:view")
	@RequestMapping(value = {"list", ""})
	public String list(DcSupTaskInfoArrange dcSupTaskInfoArrange, Model model) {
		model.addAttribute("dcSupTaskInfoArrange", dcSupTaskInfoArrange);
		return "modules/task/arrange/dcSupTaskInfoArrangeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("arrange:dcSupTaskInfoArrange:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupTaskInfoArrange> listData(DcSupTaskInfoArrange dcSupTaskInfoArrange, HttpServletRequest request, HttpServletResponse response) {
		dcSupTaskInfoArrange.setPage(new Page<>(request, response));
		Page<DcSupTaskInfoArrange> page = dcSupTaskInfoArrangeService.findPage(dcSupTaskInfoArrange);
		return page;
	}

	/**
	 * 查询最新整理任务历史
	 */
	@RequestMapping(value = "getLastedArrange")
	public String getLastedArrange(DcSupTaskInfoArrange dcSupTaskInfoArrange, Model model) {
		dcSupTaskInfoArrange.setArrangeStatus("2");
		List<DcSupTaskInfoArrange> list = dcSupTaskInfoArrangeService.findList(dcSupTaskInfoArrange);
		if(list != null && list.size()>0){
			model.addAttribute("dcSupTaskInfoArrange", list.get(0));
		}

		return "modules/task/arrange/dcSupTaskLastestArrange";
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("arrange:dcSupTaskInfoArrange:view")
	@RequestMapping(value = "form")
	public String form(DcSupTaskInfoArrange dcSupTaskInfoArrange, Model model) {
		model.addAttribute("dcSupTaskInfoArrange", dcSupTaskInfoArrange);
		return "modules/task/arrange/dcSupTaskInfoArrangeForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("arrange:dcSupTaskInfoArrange:edit")
	@PostMapping(value = "save")
	@RepeatSubmit
	@ResponseBody
	public String save(@Validated DcSupTaskInfoArrange dcSupTaskInfoArrange) {
		dcSupTaskInfoArrangeService.save(dcSupTaskInfoArrange);
		return renderResult(Global.TRUE, text("保存任务部署信息-整理任务成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("arrange:dcSupTaskInfoArrange:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupTaskInfoArrange dcSupTaskInfoArrange) {
		dcSupTaskInfoArrangeService.delete(dcSupTaskInfoArrange);
		return renderResult(Global.TRUE, text("删除任务部署信息-整理任务成功！"));
	}
	
}